package com.kts.setting;

import com.pref.Dialogs.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class Settings extends Activity {
    /** Called when the activity is first created. */
	private static final int EDIT_ID = Menu.FIRST+2;
	private static final int CLOSE_ID = Menu.FIRST+4;
	
	private TextView username=null;
	private TextView languagelist=null;
	private TextView checkbox=null;
//	private TextView ringtone=null;
//	private TextView checkbox2=null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		username=(TextView)findViewById(R.id.username);
		languagelist=(TextView)findViewById(R.id.languagelist);
		checkbox=(TextView)findViewById(R.id.checkbox);
//		ringtone=(TextView)findViewById(R.id.ringtone);
//		checkbox2=(TextView)findViewById(R.id.checkbox2);

	}
	
	@Override
	public void onResume() {
		super.onResume();
		
		SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
		
		username.setText(prefs.getString("username", "<unset>"));
		languagelist.setText(prefs.getString("languagelist", "<unset>"));
		
		checkbox.setText(new Boolean(prefs.getBoolean("checkbox", false))
												.toString());
//		ringtone.setText(prefs.getString("ringtone", "<unset>"));
//		checkbox2.setText(new Boolean(prefs.getBoolean("checkbox2", false))
//												.toString());

	}
	
	// Menu
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, EDIT_ID, Menu.NONE, "Edit Prefs")
				.setIcon(R.drawable.misc)
				.setAlphabeticShortcut('e');
		menu.add(Menu.NONE, CLOSE_ID, Menu.NONE, "Close")
				.setIcon(R.drawable.eject)
				.setAlphabeticShortcut('c');

		return(super.onCreateOptionsMenu(menu));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case EDIT_ID:
				startActivity(new Intent(this, EditPreferences.class));
				return(true);
				
			case CLOSE_ID:
				finish();
				return(true);
		}

		return(super.onOptionsItemSelected(item));
	}
}